;
$(document).ready(function() {
	var timeSign=false;
	var time=60;
	require(weburl + model_codePass, "json", "post", {
		token: localStorage.getItem("token")
	}, function(response) {
		console.log(JSON.stringify(response));
		var res = response.data.list;
		var count = 0;
		if(response.status == "success") {
			for(var key in res) {
				var str = "";
				for(var i in res[key]) {
					str += '<li class="mui-table-view-cell"><div class="mui-input-row mui-radio"><label>' + res[key][i].desc_pay + '</label><input name="' + ((count == 0) ? "name1" : "name2") + '" type="radio" checked="'+((res[key][i].Selected==1)?"checked":"")+'" data-id="' + res[key][i].store_type + '"> </div> </li>';
				}
				console.log(str);
				if(count == 0) {
					$(".pass_type").eq(0).append(str);
				} else if(count == 1) {
					$(".pass_type").eq(1).append(str);
				}
				count++;
			}
		}
	}, function() {
		mui.toast("通道查询失败", " ", "关闭", function() {}, "div");
	})
	//点击获取验证码
	mui("body").on("tap", ".yzm", function() {
		$("#yzm").blur();
		mui.confirm("将发送验证码至" + localStorage.getItem("USERID") + "手机", " ", ["发送", "关闭"], function(e) {
			if(e.index == 0) {
				plus.nativeUI.showWaiting("短信发送中，请勿退出...");
				require(weburl + model_sendY, "json", "post", {
					phone: localStorage.getItem("USERID"),
					token: localStorage.getItem("token")
				}, function(response) {
					plus.nativeUI.closeWaiting();
					if (timeSign==false) {
						var setInt=setInterval(function(){
							if (time>0) {
								timeSign=true;
								time--;
								$(".yzm").html(time+"s后重发");
								$(".yzm").css("background-color","#C7C7CC");
								return false;
							}
							time=60;
							$(".yzm").html("验证码");
							$(".yzm").css("background-color","#f0ad4e");
							
							clearInterval(setInt);
						},1000);
					}
					mui.alert(response.msg, " ", "关闭", function() {}, "div");
				}, function() {
					plus.nativeUI.closeWaiting();
					mui.alert("发送验证码失败，请稍后再试", " ", "关闭", function() {}, "div");
				})
			}
		}, "div")
	})
	//点击修改通道
	mui("body").on("tap", ".change", function() {
		$("#yzm").blur();
		var alipay_pass = $("input[name='name1']:checked").attr("data-id");
		var weixin_pass = $("input[name='name2']:checked").attr("data-id");
		var code = $("#yzm").val();
		if(code) {
			plus.nativeUI.showWaiting("正在处理中，请勿退出...");
			require(weburl + model_codeChange, "json", "post", {
				token: localStorage.getItem("token"),
				alipay: alipay_pass,
				weixin: weixin_pass,
				code:code,
				phone:localStorage.getItem("USERID")
			}, function(response) {
				plus.nativeUI.closeWaiting();
				console.log(JSON.stringify(response));
				mui.alert(response.msg, " ", "关闭", function() {}, "div");
			}, function() {
				plus.nativeUI.closeWaiting();
				mui.alert("通道设置失败，请稍后再试", " ", "关闭", function() {}, "div");
			})
			return false;
		}
		mui.alert("验证码不能为空", " ", "关闭", function() {}, "div");
	})
})